import java.util.Properties

import org.apache.kylin.jdbc.Driver

object KylinJDBCQuery {
  def main(args: Array[String]): Unit = {


    val driver: Driver = Class.forName("org.apache.kylin.jdbc.Driver").newInstance.asInstanceOf[Driver]

    val prop = new Properties()
    prop.setProperty("user", "ADMIN")
    prop.setProperty("password", "KYLIN")
    val connection = driver.connect("jdbc:kylin://doitedu03:7070/pv_analitic_model", prop)

    val statement = connection.prepareStatement("select province,city,region,sum(pv_cnt) as pv_amt from test.dws_pv_se where dtstr=? group by province,city,region")
    statement.setString(1, "2020-08-17")

    val resultSet = statement.executeQuery()

    while (resultSet.next()) {
      val province = resultSet.getString(1)
      val city = resultSet.getString(2)
      val region = resultSet.getString(3)
      val pv_amt = resultSet.getLong(4)
      print(province + "\t" + city + "\t" + region + "\t" + pv_amt)
      println()
    }

    resultSet.close()
    statement.close()
    connection.close()
  }

}
